local extension = Package("blitz_coldpalace")
extension.extensionName = "zenless__teyvat"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
    ["blitz_coldpalace"] = "闪击·不可知域",
  }

local Kongyiji = General(extension, "blitz__Kongyiji", "qun", 3, 4, General.Male)
local Naifeilita = General(extension, "blitz__Naifeilita", "Void", 2, 5, General.Female) 
local Bennett = General(extension, "blitz__Bennett", "Mondstadt", 4, 4, General.Male)
local Eden = General(extension, "blitz__Eden", "god", 3, 3, General.Female)

Kongyiji.hidden = true
Naifeilita.hidden = true
Bennett.hidden = true
Eden.hidden = true

--无法定位到{因顺手牵羊}获得的牌，原来这个写法很危险，插入结算就出事了，闹了半天才知道顺手自己的问题，太坏太坏
--不过我也不可能改底层代码，那就改牌吧
local blitz__daozuqieyou_snatchSkill = fk.CreateActiveSkill{
  name = "blitz__daozuqieyou_snatchSkill",
  prompt = "#snatch_skill",
  can_use = Util.CanUse,
  distance_limit = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local player = Fk:currentRoom():getPlayerById(to_select)
    local from = Fk:currentRoom():getPlayerById(user)
    return from ~= player and not (player:isAllNude() or (distance_limited and not self:withinDistanceLimit(from, false, card, player)))
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data, player)
    local count_distances = not (extra_data and extra_data.bypass_distances)
    if not Util.TargetFilter(self, to_select, selected, _, card, extra_data, player) then return end
    return self:modTargetFilter(to_select, selected, player, card, count_distances)
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if from.dead or to.dead or to:isAllNude() then return end
    local cid = room:askForCardChosen(from, to, "hej", self.name)
    room:obtainCard(from, cid, false, fk.ReasonPrey, from.id, "blitz__daozuqieyou_snatchSkill")
  end
}
blitz__daozuqieyou_snatchSkill.cardSkill = true
Fk:addSkill(blitz__daozuqieyou_snatchSkill)
local blitz__sihuisongzhi = fk.CreateViewAsSkill{
  name = "blitz__sihuisongzhi",
  pattern = ".",
  prompt = "#blitz__sihuisongzhi",
  interaction = function(self)
    local all_names , names = Self:getMark("@$blitz__sihuisongzhi") , {}
    for i = 1, #all_names, 1 do
      local card_name = all_names[i]
      all_names[i] = "blitz__sihuisongzhi_index:::"..i..":"..card_name
      if Self:getMark("blitz__sihuisongzhi"..i.."-turn") == 0 then
        table.insert(names, all_names[i])
      end
    end
    if #names > 0 then
    return UI.ComboBox {
      choices = names,
      all_choices = all_names,
    }
    end
  end,
  card_filter = function(self, to_select, selected)
    local handcards = Self:getCardIds("h")
    if #selected == 0 and #handcards == 1 and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip then
      return true
    end
  end,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local n = #Self:getCardIds("h")
    if not (#cards == 1 and n == 1) then return end
    local card = Fk:cloneCard(string.split(self.interaction.data, ":")[5])
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "blitz__sihuisongzhi"..string.split(self.interaction.data, ":")[4].."-turn", 1)
  end,
  enabled_at_play = function(self, player)
    local mark = Self:getTableMark("@$blitz__sihuisongzhi")
    return #mark > 0
  end,
  enabled_at_response = function(self, player, response)
    if player:getHandcardNum() == 1 and Fk.currentResponsePattern and response then
    local mark = Self:getTableMark("@$blitz__sihuisongzhi")
    for i = 1, #mark, 1 do
      if player:getMark("blitz__sihuisongzhi"..i.."-turn") == 0 then
        if Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(mark[i])) then
          return true
        end
      end
    end
  end
  end,

  on_acquire = function (self, player, is_start)
    if is_start then
    player.room:setPlayerMark(player, "@$blitz__sihuisongzhi", U.getUniversalCards(player.room, "bt"))
    player.room:askForUseActiveSkill(player, "blitz__sihuisongzhi_active", "#blitz__sihuisongzhi-ask", false)
    end
  end,
}
local blitz__sihuisongzhi_active = fk.CreateActiveSkill{
  name = "blitz__sihuisongzhi_active",
  pattern = ".",
  min_card_num = 1,
  max_card_num = 4,
  anim_type = "special",
  prompt = "#blitz__sihuisongzhi_active",
  expand_pile = function() return Self:getTableMark("@$blitz__sihuisongzhi") end,
  card_filter = function(self, to_select, selected)
    local x = 0
    for _, id in ipairs(selected) do
      x = x + Fk:translate(Fk:getCardById(id).trueName, "zh_CN"):len()
    end
    if table.contains(Self:getTableMark("@$blitz__sihuisongzhi"), to_select)
    and Fk:translate(Fk:getCardById(to_select).trueName, "zh_CN"):len() <= 4 then
    return (x <= 4 and Fk:translate(Fk:getCardById(to_select).trueName, "zh_CN"):len() + x <= 4)
    or Fk:translate(Fk:getCardById(to_select).trueName, "zh_CN"):len() + x == 4
    end
  end,
  feasible = function (self, selected, selected_cards)
    local x = 0
    for _, id in ipairs(selected_cards) do
      x = x + Fk:translate(Fk:getCardById(id).trueName, "zh_CN"):len()
    end
    return x == 4
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local mark = player:getMark("@$blitz__sihuisongzhi")
    for _, id in ipairs(U.getUniversalCards(player.room, "bt")) do
      table.removeOne(mark, id)
    end
    room:setPlayerMark(player, "@$blitz__sihuisongzhi", 0)
    local cards = effect.cards
    for _, id in ipairs(cards) do
      table.insert(mark, Fk:getCardById(id).name)
    end
    room:setPlayerMark(player, "@$blitz__sihuisongzhi", #mark and mark or 0)
  end,
}
local blitz__daozuqieyou = fk.CreateActiveSkill{
  name = "blitz__daozuqieyou",
  anim_type = "control",
  prompt = function(self)
    if self.interaction.data == "blitz__daozuqieyou1" then
      return "#blitz__daozuqieyou1"
    elseif self.interaction.data == "blitz__daozuqieyou2" then
      return "#blitz__daozuqieyou2"
    end
  end,
  interaction = function(self)
    local names = {}
    if Self:usedSkillTimes(self.name, Player.HistoryPhase) == 0 then
      table.insertIfNeed(names, "blitz__daozuqieyou1")
    end
    if Self:usedSkillTimes(self.name, Player.HistoryTurn) > 0 then
      table.insertIfNeed(names, "blitz__daozuqieyou2")
    end
    if #names > 0 then
    return UI.ComboBox {choices = names}
    end
  end,
  can_use = function(self, player)
    if self.interaction.data == "blitz__daozuqieyou1" then
    return not player:isKongcheng()
  else
    return not player:isNude()
    end
  end,
  card_filter = function(self, to_select, selected)
    return self.interaction.data == "blitz__daozuqieyou2" and #selected == 0 and
    table.contains(Self:getTableMark("@$blitz__daozuqieyou-turn"), Fk:getCardById(to_select).name)
    and not Self:prohibitUse(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return self.interaction.data == "blitz__daozuqieyou2" and #selected == 0
    and Self:canUseTo(Fk:cloneCard("snatch"), target)
  end,
  feasible = function(self, selected, selected_cards)
    if self.interaction.data == "blitz__daozuqieyou1" then
    return #selected_cards == 0
    end
    return #selected_cards == 1
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if self.interaction.data == "blitz__daozuqieyou1" then
      local mark = player:getTableMark("@$blitz__daozuqieyou-turn")
      for _, id in ipairs(player:getCardIds("h")) do
        table.insertIfNeed(mark, Fk:getCardById(id).name)
      end
      room:recastCard(player:getCardIds("h"), player, self.name)
      room:setPlayerMark(player, "@$blitz__daozuqieyou-turn", #mark and mark or 0)
    elseif self.interaction.data == "blitz__daozuqieyou2" then
      local snatch = Fk:cloneCard("snatch")
      snatch.skillName = self.name
      snatch.skill = blitz__daozuqieyou_snatchSkill
      local cards = effect.cards
        for _, id in ipairs(cards) do
          snatch:addSubcard(id)
        end
        local use = {
          from = player.id,
          card = snatch,
          tos = { { target.id } },
        }
        use.extra_data = use.extra_data or {}
        use.extra_data.daozuqieyou_user = player.id
        room:useCard(use)
    end
  end,
}
local blitz__daozuqieyou_delay = fk.CreateTriggerSkill{
  name = "#blitz__daozuqieyou_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return not player.dead and table.contains(data.card.skillNames, "blitz__daozuqieyou")
    and data.extra_data and data.extra_data.daozuqieyou_user == player.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local ids = player:getTableMark("daozuqieyou")
    local cards = table.filter(ids, function (id)
      return table.contains(player:getCardIds("h"), id)
    end)
    player:showCards(cards)
    player.room:setPlayerMark(player, "daozuqieyou", 0)
    for _, cardId in ipairs(cards) do
    if not table.contains(player:getTableMark("@$blitz__daozuqieyou-turn"), Fk:getCardById(cardId).name) then
      player.room:loseHp(player, 1, self.name)
      local targets = player.room:askForChooseToMoveCardInBoard(player, "#daozuqieyou-move", self.name, true)
      if #targets ~= 0 then
        player.room:askForMoveCardInBoard(player, player.room:getPlayerById(targets[1]), player.room:getPlayerById(targets[2]), self.name)
      else 
        player.room:changeMaxHp(player, -1)
        player:drawCards(player.maxHp, self.name)
      end
    end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonPrey and move.skillName == "blitz__daozuqieyou_snatchSkill" then
        local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event ~= nil then
          local use = use_event.data[1]
          if (use.extra_data or {}).daozuqieyou_user == player.id then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local ids = player:getTableMark("daozuqieyou")
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if player.room:getCardArea(info.cardId) == Card.PlayerHand then
          table.insertIfNeed(ids, info.cardId)
         end
      end
    end
    player.room:setPlayerMark(player, "daozuqieyou", #ids > 0 and ids or 0)
  end,
}
Fk:addSkill(blitz__sihuisongzhi_active)
blitz__daozuqieyou:addRelatedSkill(blitz__daozuqieyou_delay)
Kongyiji:addSkill(blitz__sihuisongzhi)
Kongyiji:addSkill(blitz__daozuqieyou)
Fk:loadTranslationTable{
  ["blitz__Kongyiji"] = "孔乙己", 
  ["#blitz__Kongyiji"] = "恐疑己",
  ["cv:blitz__Kongyiji"] = "暂无",
  ["illustrator:blitz__Kongyiji"] = "未知",
  ["designer:blitz__Kongyiji"] = "墨客",

  ["blitz__sihuisongzhi"] = "四“回”颂之",
  [":blitz__sihuisongzhi"] = "游戏开始时，你声明共计四字的即时牌名；你可将最后一张手牌当其中一个牌名使用或打出（每回合每种牌名限一次）。",
  ["blitz__daozuqieyou"] = "蹈俎窃诱",
  [":blitz__daozuqieyou"] = "出牌阶段限一次，你可重铸所有手牌，然后本回合你可以将与任意本回合因此重铸牌的同名牌当【顺手牵羊】使用。<br>"..
  "因此使用【顺手牵羊】结算后，你展示获得的牌，若与所有本回合因此重铸牌异名，你失去1点体力，然后选择一项：①减1点体力上限，然后摸体力上限数牌；②移动场上一张牌。",
  ["blitz__sihuisongzhi_active"] = "四“回”颂之",
  ["@$blitz__sihuisongzhi"] = "四“回”颂之",
  ["blitz__sihuisongzhi_index"] = "[%arg] "..Fk:translate("%arg2"),
  ["#blitz__sihuisongzhi-ask"] = "四“回”颂之：请选择其中任意个牌名（字数和需等于四）",
  ["#blitz__sihuisongzhi_active"] = "四“回”颂之：请选择其中任意个牌名（字数和需等于四）",
  ["#blitz__sihuisongzhi"] = "四“回”颂之：请将最后一张手牌当牌表中的一个牌名使用或打出（每回合每种牌名限一次）",
  ["@$blitz__daozuqieyou-turn"] = "蹈俎窃诱",
  ["#blitz__daozuqieyou_delay"] = "蹈俎窃诱",
  ["blitz__daozuqieyou1"] = "重铸所有手牌（直接确定）",
  ["blitz__daozuqieyou2"] = "转化顺手牵羊（选择牌与目标）",
  ["#blitz__daozuqieyou1"] = "是否发动 蹈俎窃诱，重铸所有手牌？",
  ["#blitz__daozuqieyou2"] = "是否发动 蹈俎窃诱，转化顺手牵羊（选择牌与目标）？",
  ["#daozuqieyou-move"] = "蹈俎窃诱：请移动场上一张牌，否则减1点体力上限并摸体力上限张牌！",
  ["blitz__daozuqieyou_snatchSkill"] = "顺手牵羊",

  ["~blitz__Kongyiji"] = "…",
} --孔乙己(完成)

local blitz__lingdun = fk.CreateTriggerSkill{
  name = "blitz__lingdun",
  anim_type = "defensive",
  events = {fk.TurnStart, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
    return true
    elseif event == fk.TurnEnd then
    local y = player.shield
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 0, y,
    "#blitz__lingdun_0", self.name, true)
    if #tos > 0 then
    self.cost_data = {tos = tos}
    return true
    end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
    local x = player.hp
    room:changeShield(player, x)
  elseif event == fk.TurnEnd then
    local targets = table.simpleClone(self.cost_data.tos)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local p = room:getPlayerById(id)
      room:setPlayerMark(p, "@@blitz__lingdun", 1)
    end
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill(self,true) then return false end
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:setPlayerMark(p, "@@blitz__lingdun", 0)
    end
  end,
}
local blitz__lingdun_trigger = fk.CreateTriggerSkill{
  name = "#blitz__lingdun_trigger",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target:getMark("@@blitz__lingdun") > 0
    and data.to ~= player and not (data.extra_data and (data.extra_data or {}).blitzlingdunBearer == player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage{
      from = data.from,
      to = player,
      damage = data.damage,
      damageType = data.damageType,
      skillName = data.skillName, 
      chain = data.chain,
      card = data.card,
      extra_data = { blitzlingdunBearer = player.id } --为了防止复制技能击鼓传花，以及二技能监听方便...
    }
    if not player.dead then
      player:drawCards(data.damage, self.name)
    end
    return true
  end,
}
local blitz__lianxie = fk.CreateTriggerSkill{
  name = "blitz__lianxie",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("blitz__lianxie") > 0 and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local invoke = player.room:askForSkillInvoke(player, self.name, nil, "#blitz__lianxie-invoke:")
    if invoke then
      return true
    else
      player.room:setPlayerMark(player ,"blitz__lianxie" ,0)
      return false
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = 0
    x = x + player:getMark("blitz__lianxie")

    for i = 1, x, 1 do
      if not player.dead then
      local choices = {"slashplus","drawplus","cancel"}
      local choice = room:askForChoice(player, choices, self.name, "#blitz__lianxie-support:::".. i .. ":" .. x, false, {"slashplus","drawplus","cancel"})
      if choice == "slashplus" then
      room:addPlayerMark(player, MarkEnum.SlashResidue.."-turn", 1)
      elseif choice == "drawplus" then
      room:addPlayerMark(player, "MarkEnum.DrawPlus-turn", 1)
      elseif choice == "cancel" then
      room:setPlayerMark(player ,"blitz__lianxie" ,0)
      break
      end
      end
    end
  end,

  refresh_events = {fk.HpChanged},
  can_refresh = function (self, event, target, player, data)
    if target == player and player.shield == 0 and data.reason == "damage" and data.num < 0 then
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.Damage)
    if e then
      local damage = e.data[1]
      return (damage.extra_data or {}).blitzlingdunBearer == player.id
    end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "blitz__lianxie", 1)
  end,
}
local DrawPlus_trigger = fk.CreateTriggerSkill{
  name = "#DrawPlus_trigger",
  mute = true,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target:getMark("MarkEnum.DrawPlus-turn") > 0 and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.n = data.n + target:getMark("MarkEnum.DrawPlus-turn")
  end,
}
blitz__lianxie:addRelatedSkill(DrawPlus_trigger)
blitz__lingdun:addRelatedSkill(blitz__lingdun_trigger)
Naifeilita:addSkill(blitz__lingdun)
Naifeilita:addSkill(blitz__lianxie)
Fk:loadTranslationTable{
  ["blitz__Naifeilita"] = "奈菲利塔", 
  ["#blitz__Naifeilita"] = "虚构之神",
  ["cv:blitz__Naifeilita"] = "奥奇传说",
  ["illustrator:blitz__Naifeilita"] = "奥奇传说",
  ["designer:blitz__Naifeilita"] = "Silverash.",

  ["blitz__lingdun"] = "灵盾",
  [":blitz__lingdun"] = "回合开始时，你获得体力值点护甲。回合结束时，你可以选择至多护甲值名其他角色，直至你下回合开始，这些角色受到伤害时，将此伤害转移给你，然后你摸伤害值张牌。",
  ["blitz__lianxie"] = "连携",
  [":blitz__lianxie"] = "你因“灵盾”扣减体力值后，你可以于你下回合的准备阶段选择一项：本回合摸牌阶段多摸一张牌；或本回合使用【杀】的次数+1。",
  ["#blitz__lingdun_0"] = "灵盾：选择至多护甲值名角色，直至你下回合开始，你代为承受这些角色受到的伤害。",
  ["@@blitz__lingdun"] = "灵盾 转伤",
  ["drawplus"] = "本回合摸牌阶段摸牌数+1",
  ["#blitz__lingdun_trigger"] = "灵盾",
  ["#blitz__lianxie-support"] = "连携：选择一项执行（%arg/%arg2），选择取消则中止。",
  ["#blitz__lianxie-invoke"] = "连携：是否选择增加于本回合的摸牌数或使用【杀】的上限？",
  ["#DrawPlus_trigger"] = "",

  ["~blitz__Naifeilita"] = "…",
} --奈菲利塔(完成)

local blitz__lixinli = fk.CreateTriggerSkill{
  name = "blitz__lixinli",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    table.insertTable(cards, room:getCardsFromPileByRule("amazing_grace|.|.|.|.|.", 1, "allPiles"))
    table.insertTable(cards, room:getCardsFromPileByRule("collateral|.|.|.|.|.", 1, "allPiles"))
    table.insertTable(cards, room:getCardsFromPileByRule("lightning|.|.|.|.|.", 1, "allPiles"))
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
      return true
    end
  end,
}
local blitz__lixinxin = fk.CreateTriggerSkill{
  name = "blitz__lixinxin",
  anim_type = "special",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local targets = AimGroup:getAllTargets(data.tos)
    if player:hasSkill(self) and (table.contains(targets, player.id) or target == player)
    and not (data.extra_data and data.extra_data.blitz__lixinxin == player.id) then
      local use_event = room.logic:getCurrentEvent()
      local last_tos = {}
      local sameuser = true
      room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
        if e.id < use_event.id then
          local use = e.data[1]
          last_tos = TargetGroup:getRealTargets(use.tos)
          if use.from ~= target.id then
            sameuser = false
          end
          return true
        end
      end, 0)
      if #last_tos == 0 or not sameuser then return false end
      if table.every(room.alive_players, function (p)
        return (table.contains(targets, p.id) and table.contains(last_tos, p.id)) or
        (not table.contains(targets, p.id) and not table.contains(last_tos, p.id))
      end) then
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.extra_data = data.extra_data or {}
    data.extra_data.blitz__lixinxin = player.id
    local use = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use ~= nil then
      local new_card = Fk:cloneCard("fire__slash", data.card.suit, data.card.number)
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        if new_card[k] == nil then
          new_card[k] = v
        end
      end
      if data.card:isVirtual() then
        new_card.subcards = data.card.subcards
      else
        new_card.id = data.card.id
      end
      new_card.skillNames = data.card.skillNames
      new_card.skill = Fk.skills["fire__slash_skill"]
      data.card = new_card
      use.data[1].card = new_card
    end
  end,
}
local blitz__lixinxin_delay = fk.CreateTriggerSkill{
  name = "#blitz__lixinxin_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.blitz__lixinxin and data.extra_data.blitz__lixinxin == player.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    local choices = {"recover", "drawTargets"}
    if table.every(targets, function (p)
      return not target:canUseTo(Fk:cloneCard("fire__slash"), room:getPlayerById(p), { bypass_times = true, bypass_distances= true }) 
    end) then
      table.insert(choices, 1, "noretreat")
    end
    local choice = room:askForChoice(player, choices, self.name, "#blitz__lixinxin-reward", false, {"recover", "drawTargets", "noretreat"})
    if choice ~= "drawTargets" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    if choice ~= "recover" then
      player:drawCards(#targets, self.name)
    end
  end,
}
blitz__lixinxin:addRelatedSkill(blitz__lixinxin_delay)
Bennett:addSkill(blitz__lixinli)
Bennett:addSkill(blitz__lixinxin)

Fk:loadTranslationTable{
  ["blitz__Bennett"] = "班尼特", 
  ["#blitz__Bennett"] = "命运试金石",
  ["cv:blitz__Bennett"] = "穆雪婷",
  ["illustrator:blitz__Bennett"] = "Alan兰懒",
  ["designer:blitz__Bennett"] = "冷若寒",

  ["blitz__lixinli"] = "历辛",
  [":blitz__lixinli"] = "锁定技，摸牌阶段，若你能从牌堆或弃牌堆中获得至少一张下列牌，你改为从这些区域获得【五谷丰登】，【借刀杀人】和【闪电】各一张。",
  ["blitz__lixinxin"] = "砺心",
  [":blitz__lixinxin"] = "锁定技，一名角色使用牌时，若使用者和目标与上一张被使用的牌完全相同，且使用者或至少一个目标为你，此牌的效果改为火【杀】。"..
  "结算完成后，你摸等同于目标数的牌或回复1点体力（若所有目标均不为使用者使用【杀】（无视距离、次数）的合法目标，你可以背水）。",
  ["#blitz__lixinxin_delay"] = "砺心",
  ["#blitz__lixinxin-reward"] = "砺心：请选择一项后续效果",
  ["drawTargets"] = "摸目标数张牌",
  ["noretreat"] = "上述两项均选",

  ["$blitz__lixinli1"] = "冒险冒险！",
  ["$blitz__lixinli2"] = "不如在周围找找看吧，说不定有宝藏呢！",
  ["$blitz__lixinxin1"] = "烧起来吧！",
  ["$blitz__lixinxin2"] = "有大家在身边，伤口就不会痛！",
  ["~blitz__Bennett"] = "不出意料的，坏运气…",
} --班尼特(完成)

local blitz__huangjin = fk.CreateTriggerSkill{
  name = "blitz__huangjin",
  anim_type = "drawcard",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@blitz__huangjin", data.card.number)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.GameStart, fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    else
      return target == player and player:hasSkill(self, true, true)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart or event == fk.EventAcquireSkill then
      if player:hasSkill(self, true) then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          room:handleAddLoseSkills(p, "blitz__huangjin&", nil, false, true)
        end
      end
    elseif event == fk.EventLoseSkill or event == fk.Deathed then
      for _, p in ipairs(room:getOtherPlayers(player, true, true)) do
        room:handleAddLoseSkills(p, "-blitz__huangjin&", nil, false, true)
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    local room = player.room
      room:setPlayerMark(player, "@blitz__huangjin", 4)
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
      room:setPlayerMark(player, "@blitz__huangjin", 0)
  end,
}
local blitz__huangjin_active = fk.CreateActiveSkill{
  name = "blitz__huangjin&",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#blitz__huangjin&",
  can_use = function(self, player)
    local targetRecorded = player:getTableMark("blitz__huangjin_targets-phase")
    return table.find(Fk:currentRoom().alive_players, function(p)
      return p ~= player and p:hasSkill(blitz__huangjin, true) and not table.contains(targetRecorded, p.id)
    end)
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):hasSkill(blitz__huangjin) and
    not table.contains(Self:getTableMark("blitz__huangjin_targets-phase"), to_select)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    target:broadcastSkillInvoke("blitz__huangjin")
    room:addTableMarkIfNeed(player, "blitz__huangjin_targets-phase", target.id)
    local id = effect.cards[1]
    room:setPlayerMark(target, "@blitz__huangjin", Fk:getCardById(id).number)
    room:obtainCard(target.id, id, false, fk.ReasonGive, player.id)
  end,
}
local blitz__huazhang = fk.CreateActiveSkill{
  name = "blitz__huazhang",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = "#blitz__huazhang",
  can_use = function(self, player)
    return not player:isNude()
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local num = 0
    for _, id in ipairs(selected_cards) do
      num = num + Fk:getCardById(id).number
    end
    num = num % 13
    num = num == 0 and 13 or num
    return #selected_cards >= 2 and num == Self:getMark("@blitz__huangjin") and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if not player:isKongcheng() then
    local cards = room:askForCard(player, 1, 1, false, self.name, false, ".", "#blitz__huazhang-invoke")
    room:setCardMark(Fk:getCardById(cards[1]), "@@blitz__huazhang", 1)
    player:addToPile("blitz__huazhang_music", cards, true, self.name)
    if #player:getPile("blitz__huazhang_music") % 2 == 0 then
      room:setPlayerMark(player, "@@blitz__huazhang1", 1)
      room:setPlayerMark(player, "@@blitz__huazhang2", 0)
    else
      room:setPlayerMark(player, "@@blitz__huazhang2", 1)
      room:setPlayerMark(player, "@@blitz__huazhang1", 0)
    end
    end
  end,

  on_acquire = function (self, player, is_start)
    local room = player.room
    if #player:getPile("blitz__huazhang_music") % 2 == 0 then
      room:setPlayerMark(player, "@@blitz__huazhang1", 1)
      room:setPlayerMark(player, "@@blitz__huazhang2", 0)
    else
      room:setPlayerMark(player, "@@blitz__huazhang2", 1)
      room:setPlayerMark(player, "@@blitz__huazhang1", 0)
    end
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    room:setPlayerMark(player, "@@blitz__huazhang2", 0)
    room:setPlayerMark(player, "@@blitz__huazhang1", 0)
  end,
}
--这里做一点处理：若有至少两名角色获得华章，华章锁牌的效果失效（防止人为锁大锁小制造恶性死局）
local blitz__huazhang_prohibit = fk.CreateProhibitSkill{
  name = "#blitz__huazhang_prohibit",
  prohibit_use = function(self, player, card)
    if #table.filter(Fk:currentRoom().alive_players, function(p) return p:hasSkill(blitz__huazhang) end) == 1 then
    local current = table.find(Fk:currentRoom().alive_players, function(p) return p:hasSkill(blitz__huazhang) end)
      if #current:getPile("blitz__huazhang_music") % 2 == 0 then
        return card.number < current:getMark("@blitz__huangjin")
      else
        return card.number > current:getMark("@blitz__huangjin")
      end
    end
  end,
}
local blitz__jiuyi = fk.CreateActiveSkill{
  name = "blitz__jiuyi",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 and #player:getPile("blitz__huazhang_music") > 0
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:obtainCard(player, player:getPile("blitz__huazhang_music"), true)
    if #player:getPile("blitz__huazhang_music") % 2 == 0 then
      room:setPlayerMark(player, "@@blitz__huazhang1", 1)
      room:setPlayerMark(player, "@@blitz__huazhang2", 0)
    else
      room:setPlayerMark(player, "@@blitz__huazhang2", 1)
      room:setPlayerMark(player, "@@blitz__huazhang1", 0)
    end
    room:setPlayerMark(player, "@@blitz__jiuyi", 1)
  end,
}
local blitz__jiuyi_filter = fk.CreateFilterSkill{
  name = "#blitz__jiuyi_filter",
  card_filter = function(self, card, player, isJudgeEvent)
    return player:hasSkill(self) and player:getMark("@@blitz__jiuyi") > 0 and card:getMark("@@blitz__huazhang") == 0
    and (table.contains(player.player_cards[Player.Hand], card.id))
  end,
  view_as = function(self, card)
    return Fk:cloneCard("jink", card.suit, card.number)
  end,
}
local blitz__jiuyi_trigger  = fk.CreateTriggerSkill{
  name = "#blitz__jiuyi_trigger",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local ids = {}
      local room = player.room
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId):getMark("@@blitz__huazhang") > 0 and
              room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
        end
      end
      ids = U.moveCardsHoldingAreaCheck(room, ids)
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(self.cost_data)
    for _, id in ipairs(ids) do
      room:setCardMark(Fk:getCardById(id), "@@blitz__huazhang", 1)
    end
    player:addToPile("blitz__huazhang_music", ids, true, self.name)
    if #player:getPile("blitz__huazhang_music") % 2 == 0 then
      room:setPlayerMark(player, "@@blitz__huazhang1", 1)
      room:setPlayerMark(player, "@@blitz__huazhang2", 0)
    else
      room:setPlayerMark(player, "@@blitz__huazhang2", 1)
      room:setPlayerMark(player, "@@blitz__huazhang1", 0)
    end
  end,
}
local blitz__jiuyi_trigger2 = fk.CreateTriggerSkill{
  name = "#blitz__jiuyi_trigger2",
  anim_type = "support",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing and
    data.card:getMark("@@blitz__huazhang") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("blitz__jiuyi")
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#blitz__jiuyi-choose:::"..data.card:toLogString(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(self.cost_data, data.card, true, fk.ReasonGive, player.id)
  end,
}
Fk:addSkill(blitz__huangjin_active)
blitz__huazhang:addRelatedSkill(blitz__huazhang_prohibit)
blitz__jiuyi:addRelatedSkill(blitz__jiuyi_filter)
blitz__jiuyi:addRelatedSkill(blitz__jiuyi_trigger)
blitz__jiuyi:addRelatedSkill(blitz__jiuyi_trigger2)
Eden:addSkill(blitz__huangjin)
Eden:addSkill(blitz__huazhang)
Eden:addSkill(blitz__jiuyi)
Fk:loadTranslationTable{
  ["blitz__Eden"] = "伊甸", 
  ["#blitz__Eden"] = "璀耀之歌",
  ["cv:blitz__Eden"] = "张安琪",
  ["illustrator:blitz__Eden"] = "崩坏3",
  ["designer:blitz__Eden"] = "像是繁星，黯淡了的",

  ["blitz__huangjin"] = "黄金",
  [":blitz__huangjin"] = "你获得此技能时，记录点数为4（同时只能记录一个点数）。你使用牌后，记录此牌点数并摸一张牌。"..
  "其他角色的出牌阶段限一次，其可以交给你一张牌，然后你记录该牌点数。",
  ["blitz__huazhang"] = "谐律",
  [":blitz__huazhang"] = "出牌阶段，你可以将至少两张点数之和与13取余为“黄金”所记录点数的牌交给一名其他角色，然后将一张手牌置为「华章」。"..
  "若你武将牌上“华章”牌的数量为奇/偶数，所有角色仅能使用点数不大于/不小于“黄金”记录点数的牌。<font color='grey'>测试补丁：锁牌效果仅一名角色有本技能时生效。",
  ["blitz__jiuyi"] = "旧忆",
  [":blitz__jiuyi"] = "出牌阶段限一次，你可以获得所有「华章」，若如此做，本局你的所有非「华章」手牌视为【闪】。"..
  "你使用「华章」牌结算后，你可以将其交给一名其他角色，「华章」标记牌进入弃牌堆后，你将其置于武将牌上。",
  ["blitz__huangjin&"] = "黄金",
  [":blitz__huangjin&"] = "出牌阶段限一次，你可以交给有“黄金”的角色一张牌，令其记录该牌点数。",
  ["#blitz__huangjin&"] = "出牌阶段限一次，你可以交给有“黄金”的角色一张牌，令其记录该牌点数。",
  ["@blitz__huangjin"] = "黄金",
  ["#blitz__huazhang"] = "你可以将至少两张点数之和与13取余为“黄金”所记录点数的牌交给一名其他角色",
  ["#blitz__huazhang-invoke"] = "将一张手牌置为「华章」",
  ["@@blitz__huazhang1"] = "禁小于黄金",
  ["@@blitz__huazhang2"] = "禁大于黄金",
  ["@@blitz__huazhang"] = "华章",
  ["blitz__huazhang_music"] = "华章",
  ["blitz__jiuyi_filter"] = "旧忆",  
  ["#blitz__jiuyi_trigger"] = "旧忆",
  ["#blitz__jiuyi_trigger2"] = "旧忆",
  ["#blitz__jiuyi-choose"] = "旧忆：你可以将%arg交给一名手牌数大于你的角色",
  ["@@blitz__jiuyi"] = "旧忆",

  ["$blitz__huangjin1"] = "此刻将如黄金一般闪耀。",
  ["$blitz__huangjin2"] = "真相的答案渺若星空，但虚假的谎言却多如雨霰。",
  ["$blitz__huangjin3"] = "我会永远将此刻铭记，这是一曲探寻真相的史诗。",
  ["$blitz__huazhang1"] = "去吧，奏出属于你的旋律。",
  ["$blitz__huazhang2"] = "真希望时光就此停驻，让我们得以品味这美妙的时刻。",
  ["$blitz__jiuyi1"] = "曾经的智慧与艺术，如今都埋入了黄土。",
  ["$blitz__jiuyi2"] = "歌者无数，更替无常，但艺术的舞台却永无谢幕。",
  ["$blitz__jiuyi3"] = "时光就这样流逝，如同歌声被淹没在旧日的烟尘中。",
  ["~blitz__Eden"] = "我的时代已经一曲终了，愿你们的未来能够长颂不休…",
} --伊甸(完成)

return extension